package cn.vcjf.weapp.api.active.controller;


import cn.vcjf.weapp.common.util.DateUtils;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.validation.Valid;

import org.springframework.web.bind.annotation.ResponseBody;
import cn.vcjf.weapp.common.web.TableResult;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import cn.vcjf.weapp.api.active.entity.GoodsActive;
import cn.vcjf.weapp.api.active.service.GoodsActiveService;

import org.springframework.stereotype.Controller;

import java.util.Date;

/**
 * <p>
 * 商品活动
 * </p>
 *
 * @author zhengzihang
 * @since 2018-09-26
 */
@Controller
@RequestMapping("/active/goodsActive")
public class GoodsActiveController {
	@Resource
	private GoodsActiveService goodsActiveService;

	/**
	 * 活动详情
	 *
	 * @param goodsActive
	 * @return
	 */
	@RequestMapping("/findGoodsActiveOne")
	@ResponseBody
	public TableResult findGoodsActiveOne(GoodsActive goodsActive) {

		goodsActiveService.updateExpireActive();
		GoodsActive result = goodsActiveService.findActiveInfo(goodsActive);

		return TableResult.OKResult(result);
	}

	/**
	 * 活动列表(拼团/砍价)
	 *
	 * @param goodsActive
	 * @return
	 */
	@RequestMapping("/findGoodsActiveList")
	@ResponseBody
	public TableResult findGoodsActiveList(@Valid GoodsActive goodsActive, BindingResult result) {

		TableResult.checkParams(result);
		goodsActiveService.updateExpireActive();

		EntityWrapper<GoodsActive> wrapper = goodsActive.getQueryWrapper();
		//Todo
		wrapper.orderBy("sortNo", false);
		wrapper.ge("ga.activeEndTime",new Date());
		if (goodsActive.getActivetype() == 1){

		}else if (goodsActive.getActivetype() == 2){

		}
		Page<GoodsActive> page = goodsActive.getPageInfo();

		page = goodsActiveService.selectPage(page, wrapper);

		return TableResult.OKResult(page);

	}
	/**
	 * 热门活动(拼团/砍价)
	 *
	 * @param goodsActive
	 * @return
	 */
	@RequestMapping("/findHotActiveList")
	@ResponseBody
	public TableResult selectHotActive(GoodsActive goodsActive) {

		goodsActiveService.updateExpireActive();

		EntityWrapper<GoodsActive> wrapper = goodsActive.getQueryWrapper();
		wrapper.ge("ga.activeEndTime",new Date());

		Page<GoodsActive> page = goodsActive.getPageInfo();

		page = goodsActiveService.selectHotActive(page, wrapper);

		return TableResult.OKResult(page);

	}

}
